const connection = require('../db/index')
const Mock = require('mockjs');

const routers = (data) => {
    return new Promise((resolve, reject) => {
        console.log(data);
        const { username } = data;
        resolve({
            code: 200,
            msg: "获取成功",
            data: username === "admin" ? adminRouter : commonRouter,
        })
    })
}

const menuThree = (data) => {
    return new Promise((resolve, reject) => {
        console.log(data);
        const { username } = data;
        resolve({
            code: 200,
            msg: "获取成功",
            data: filterArr(adminRouter),
        })
    })
}

const filterArr = (menus) => {
    return menus.map((item, i) => {
        if (item.children) {
            return Mock.mock({
                id: "@increment()",
                label: item.meta.title,
                children: filterArr(item.children),
            });
        } else {
            return Mock.mock({
                id: "@increment()",
                label: item.meta.title,
            });
        }
    });
};

const adminRouter = [
    {
        name: "System",
        path: "/system",
        component: "Layout",
        redirect: "/system/user",
        hidden: false,
        meta: {
            title: "系统管理",
            icon: "system",
            noCache: false,
            link: false,
        },
        children: [
            {
                name: "User",
                path: "user",
                component: "system/user/index",
                hidden: false,
                meta: {
                    title: "用户管理",
                    icon: "user",
                    noCache: false,
                    link: false,
                },
            },
            {
                name: "Role",
                path: "role",
                component: "system/role/index",
                hidden: false,
                meta: {
                    title: "角色管理",
                    icon: "role",
                    noCache: false,
                    link: false,
                },
            },
        ],
    },
    {
        name: "Ability",
        path: "/ability",
        component: "Layout",
        redirect: "/ability/test1",
        hidden: false,
        meta: {
            title: "其他功能",
            icon: "ability",
            noCache: false,
            link: false,
        },
        children: [
            {
                name: "LowCode",
                path: "lowCode",
                component: "ability/lowCode/index",
                hidden: false,
                meta: {
                    title: "低代码",
                    icon: "code",
                    noCache: false,
                    link: false,
                },
            },
            {
                name: "Color",
                path: "color",
                component: "ability/color/index",
                hidden: false,
                meta: {
                    title: "设置主题色",
                    icon: "color",
                    noCache: false,
                    link: false,
                },
            },
            {
                name: "Echarts",
                path: "echarts",
                component: "ability/echarts/index",
                hidden: false,
                meta: {
                    title: "图表展示",
                    icon: "echarts",
                    noCache: false,
                    link: false,
                },
            },
            {
                name: "Test1",
                path: "test1",
                component: "ability/test1/index",
                hidden: false,
                meta: {
                    title: "test1",
                    icon: "drag",
                    noCache: false,
                    link: false,
                },
            },
            {
                name: "Test2",
                path: "test2",
                component: "ability/test2/index",
                hidden: false,
                meta: {
                    title: "test2",
                    icon: "drag",
                    noCache: false,
                    link: false,
                },
            },
            {
                name: "跳转百度",
                path: "https://www.baidu.com/",
                component: "",
                hidden: false,
                meta: {
                    title: "百度",
                    icon: "drag",
                    noCache: false,
                    link: true,
                },
            },
        ],
    },
];

const commonRouter = [
    {
        name: "Drag",
        path: "/drag",
        component: "Layout",
        redirect: "/drag/test1",
        hidden: false,
        meta: {
            title: "拖拽",
            icon: "drag",
            noCache: false,
            link: false,
        },
        children: [
            {
                name: "Test1",
                path: "test1",
                component: "drag/test1/index",
                hidden: false,
                meta: {
                    title: "普通用户权限1",
                    icon: "drag",
                    noCache: false,
                    link: false,
                },
            },
        ],
    },
];


module.exports = {
    routers,
    menuThree
}